package cn.tjd.smart_health.provider.service;

import cn.tjd.smart_health.api.OrderSetting;
import cn.tjd.smart_health.common.entity.ReserveSetting;
import cn.tjd.smart_health.provider.mapper.ReserveSettingMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@DubboService
public class OrderSettingImpl implements OrderSetting {

    @Autowired
    private ReserveSettingMapper orderSettingMapper;

    @Override
    public void saveOrderSettingList(List<ReserveSetting> reserveSettingList) {
        orderSettingMapper.insertOrderSettingList(reserveSettingList);
    }

    @Override
    public List<ReserveSetting> getOrderSettingList(String year, String month) {
            return orderSettingMapper.selectOrderSettingList(year,month);
    }




    @Override
    public void saveReserveSetting(ReserveSetting reserveSetting) {
        LambdaQueryWrapper<ReserveSetting> querySelect = new LambdaQueryWrapper<ReserveSetting>();
        querySelect.eq(ReserveSetting::getOrderDate, reserveSetting.getOrderDate());
        List<ReserveSetting> reserveSettingList = orderSettingMapper.selectList(querySelect);
        if (reserveSettingList.size() == 0) {
            orderSettingMapper.insert(reserveSetting);
            return;
        }
        LambdaQueryWrapper<ReserveSetting> query = new LambdaQueryWrapper();
        query.eq(ReserveSetting::getOrderDate, reserveSetting.getOrderDate());
        orderSettingMapper.update(reserveSetting,query);

    }

}
